package com.bw.flinkstreaming.source1.job1;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.ArrayList;
import java.util.List;

/**
 * 基于collect作为数据源
 */
public class FlinkSourceFromCollection {


    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        //数据源
        ArrayList<String> data = new ArrayList<String>();
        data.add("flink1");
        data.add("flink2");
        data.add("flink3");

        DataStreamSource<String> dataStreamSource = env.fromCollection(data);
        /**
         *  String,String 表示输入和输出的数据类型
         */
        SingleOutputStreamOperator<String> result = dataStreamSource.map(new MapFunction<String, String>() {
            @Override
            public String map(String value) {
//                System.out.println(value);
                return value + "collect";
            }
        });
        result.print().setParallelism(1);
        env.execute("FlinkSourceFromCollection");
    }
}
